﻿#include "OperPhysicsPropGeneralLaminate.h"
#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h"
#include "GUIDialog/GUIPhyscisDialog/PhysicsDialogGeneralLaminate.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsPhysics.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsAbsPhysicsProp.h"

#include "updateBrowserTable.h"

namespace ModelOper
{
    bool OperPhysicsPropGeneralLaminate::execGUI()
    {
        //按钮点击事件触发
        if (_emitter == nullptr) return false;
        const QString name = _emitter->objectName();
        if (name == "actionGeneralLaminate")
            createPhysicsProp();
        return false;
    }

    bool OperPhysicsPropGeneralLaminate::execProfession()
    {
        return false;
    }

    void OperPhysicsPropGeneralLaminate::createPhysicsProp()
    {
        //弹出对话框
        QWidget* mw = FITKAPP->getGlobalData()->getMainWindow();
        GUI::PhysicsDialogGeneralLaminate dlg(GUI::PhysicsDlgExecType::Create, -1, mw);
        //更新列表
        if (QDialog::Accepted == dlg.exec())
            ModelOper::updateBrowserTable();
    }

    void OperPhysicsPropGeneralLaminate::duplicatePhysicsProp(const int propID)
    {
        QWidget* mw = FITKAPP->getGlobalData()->getMainWindow();
        //编辑对话框
        GUI::PhysicsDialogGeneralLaminate dlg(GUI::PhysicsDlgExecType::Duplicate, propID, mw);
        //更新列表
        if (QDialog::Accepted == dlg.exec())
            ModelOper::updateBrowserTable();
    }

    void OperPhysicsPropGeneralLaminate::editPhysicsProp(const int propID)
    {
        QWidget* mw = FITKAPP->getGlobalData()->getMainWindow();
        //编辑对话框
        GUI::PhysicsDialogGeneralLaminate dlg(GUI::PhysicsDlgExecType::Edit, propID, mw);
        //更新列表
        if (QDialog::Accepted == dlg.exec())
            ModelOper::updateBrowserTable();
    }

    void OperPhysicsPropGeneralLaminate::removePhysicsProp(const int propID)
    {
        //获取管理器
        Acoustics::FITKAcousticsPhysics* phys = Acoustics::FITKAcousticsPhysics::GetAcousticsPhysicsFromFrame();
        if (phys == nullptr) return;
        Acoustics::FITKAcousticsPhysicsPropManager* propMgr = phys->getPhysicsPropManager();
        if (propMgr == nullptr) return;
        //移除并更新列表
        propMgr->removeDataByID(propID);
        ModelOper::updateBrowserTable();
    }

}